package com.hexinfo.dmpro.monitor.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.common.annotation.Log;
import com.hexinfo.dmpro.monitor.model.ReportResourceModel;
import com.hexinfo.dmpro.monitor.service.ReportManageService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: reportManageController
 * @Description:
 * @Author: lm.cai
 * @Date: 2021-09-16
 */
@RestController
@RequestMapping("/api/reportManageController")
public class ReportManageController {

    @Value("${rsa.private_key}")
    private String privateKey;

    @Resource
    private ReportManageService reportManageService;

    private final PasswordEncoder passwordEncoder;

    public ReportManageController(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }

    /**
     * Dashboard页 - 服务运行情况展现
     * @return
     */
    @Log("yarn作业运行情况统计")
    @GetMapping("/getYarnCurdateTaskNums")
    public ResponseEntity<Object> getYarnCurdateTaskNums(HttpServletRequest req) {
        String centerId = req.getHeader("sysKernelId");
        Map<String, Object> yarnCurdateTaskNums = reportManageService.getYarnCurdateTaskNums(centerId);
        return new ResponseEntity(yarnCurdateTaskNums, HttpStatus.OK);
    }

    @Log("impala作业运行情况统计")
    @GetMapping("/getImpalaCurdateTaskNums")
    public ResponseEntity<Object> getImpalaCurdateTaskNums(HttpServletRequest req) {
        String centerId = req.getHeader("sysKernelId");
        Map<String, Object> impalaCurdateTaskNums = reportManageService.getImpalaCurdateTaskNums(centerId);
        return new ResponseEntity(impalaCurdateTaskNums, HttpStatus.OK);
    }

    /**
     * Dashboard页 - 资源监控总体展现
     * @return
     */
    @Log("不同集群在最近24小时内的yarn内存分配率")
    @GetMapping("/getResourcefpYarn")
    public ResponseEntity<Object> getResourcefpYarn(HttpServletRequest req) {
        String centerId = req.getHeader("sysKernelId");
        return new ResponseEntity(reportManageService.getResourcefpYarn(centerId), HttpStatus.OK);
    }

    @Log("不同集群在最近24小时内的yarn内存使用率")
    @GetMapping("/getResourceUsageYarn")
    public ResponseEntity<Object> getResourceUsageYarn(HttpServletRequest req) {
        String centerId = req.getHeader("sysKernelId");
        return new ResponseEntity(reportManageService.getResourceUsageYarn(centerId), HttpStatus.OK);
    }

    @Log("不同集群在最近24小时内的Impala内存使用量")
    @GetMapping("/getResourceUsageImpala")
    public ResponseEntity<Object> getResourceUsageImpala(HttpServletRequest req) {
        String centerId = req.getHeader("sysKernelId");
        return new ResponseEntity(reportManageService.getResourceUsageImpala(centerId), HttpStatus.OK);
    }

    /**
     * 资源利用率报表页
     * @return
     */
    @Log("查询报表集群配置信息")
    @GetMapping("/selAllOptions")
    public ResponseEntity<Object> selAllOptions() {
        return new ResponseEntity(reportManageService.selAllOptions(), HttpStatus.OK);
    }

    /**
     * 资源利用率报表页
     * @return
     */
    @Log("查询报表集群配置信息")
    @PostMapping("/selAllQueue")
    public ResponseEntity<Object> selAllQueue(@RequestBody ReportResourceModel reportResourceModel) {
        return new ResponseEntity(reportManageService.selAllQueue(reportResourceModel), HttpStatus.OK);
    }

//    @Log("查询报表信息")
//    @PostMapping("/selReportInfo")
//    public ResponseEntity<Object> selReportInfo(@RequestBody ReportResourceModel reportResourceModel) {
//        return new ResponseEntity(reportManageService.selReportInfo(reportResourceModel), HttpStatus.OK);
//    }
}